package com.cq.xjms.web.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.extremecomponents.table.context.Context;
import org.extremecomponents.table.context.HttpServletRequestContext;
import org.extremecomponents.table.limit.Limit;
import org.extremecomponents.table.limit.LimitFactory;
import org.extremecomponents.table.limit.TableLimit;
import org.extremecomponents.table.limit.TableLimitFactory;

import com.opensymphony.xwork2.ActionSupport;
public class BaseAction extends ActionSupport{
	private static final long serialVersionUID = -148979817526297628L;
	public static final String INIT = "init";
	public int totalRows;
	public int pageSize;
	public int pageNo;
	public int totalPages;
	public void write(String string) {
		try {
			getResponse().setCharacterEncoding("utf-8");
			getResponse().getWriter().write(string);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	public void writeJSON(String string) {
		try {
			getResponse().setCharacterEncoding("utf-8");
			getResponse().setContentType("application/json;charset=UTF-8");
			getResponse().getWriter().write(string);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	
	protected HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	
	protected HttpServletResponse getResponse() {
		System.out.print("sss");
		return ServletActionContext.getResponse();
	}

	
	protected HttpSession getSession() {
		return getRequest().getSession();
	}
	
	
	public Limit getLimit() {
		return getLimit(10);
	}

	
	public Limit getLimit(int rowDisplay) {
		Context context = new HttpServletRequestContext(getRequest());
		LimitFactory limitFactory = new TableLimitFactory(context);
		Limit limit = new TableLimit(limitFactory);
		limit.setRowAttributes(Integer.MAX_VALUE, rowDisplay);
		return limit;
	}
	
	public int getTotalRows() {
		return totalRows;
	}
	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}
	
	
}
